/*******************************************************************************
**
** Copyright (c) 2011 - The OWE Team
**
** This file is part of OWE.
**
** OWE is a free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; version
** version 2.1 of the License.
**
** OWE is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with OWE. If not, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/

#include <owe/contentelement.h>
#include <owe/node.h>
#include <owe/ustring.h>

OWE_USE_NAMESPACE

/*!
    \class ContentElement
    \brief Widget custom start file

    \ingroup Configuration

    Implementation of the widget content element as specified
    <a href="http://www.w3.org/TR/widgets/#content">here</a>.
*/

/*!
    \fn UString ContentElement::src() const

    Returns the widget content <a href="http://www.w3.org/TR/widgets/#src0">
    src</a>
*/

/*!
    \fn UString ContentElement::encoding() const

    Returns the widget content <a href="http://www.w3.org/TR/widgets/#encoding">
    encoding</a>
*/

/*!
    \fn UString ContentElement::type() const

    Returns the widget content <a href="http://www.w3.org/TR/widgets/#type0">
    type</a>
*/

/*!
    Constructs a new ContentElement from a given \a node.
*/
ContentElement::ContentElement(const Node *node)
    : Element(node, Element::Content)
    , m_encoding(node->attribute("encoding"))
    , m_src(node->attribute("src"))
    , m_type(node->attribute("type"))
{
    if (m_encoding.size() == 0)
        m_encoding = UString("UTF-8");

    if (m_type.size() == 0)
        m_type = UString("text/html");
}

/*!
    Destructs the object releasing all allocated resources.
*/
ContentElement::~ContentElement()
{
}

/*!
    Returns whether a content is valid. In order to be valid, the content
    element must contain the src attribute.
*/
bool ContentElement::isValid() const
{
    return m_src.size() > 0;
}
